home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard Serial Toolkit 2.6 / Source Code / SPortConfiguration.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  3.6 KB  |  137 lines  |  [TEXT/MPS ]

  1. (*
  2.     SPortConfiguration() -- Returns a string containing the current configuration of the port. The string
  3.         is in the same format as the parameters passed to configureSPort.
  4.  
  5.     To compile and link this file using Macintosh Programmer's Workshop,
  6.  
  7.         pascal -w SPortConfiguration.p
  8.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=7036 -sn Main=SPortConfiguration ∂
  9.             SPortConfiguration.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o ∂
  10.             "{MPW}"Libraries:Libraries:HyperXLib.o
  11.  
  12.     © Copyright 1987,88,89 by Apple Computer, Inc.
  13.  
  14.     Initial coding 9/87 by Harry R. Chesley.
  15. *)
  16.  
  17. {$R-}
  18.  
  19. {$S SPortConfiguration }     { Segment name must be the same as the command name. }
  20.  
  21. unit DummyUnit;
  22.  
  23. interface
  24.  
  25. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  26.  
  27. procedure EntryPoint(paramPtr: XCmdPtr);
  28.     
  29. implementation
  30.  
  31. procedure SPortConfiguration(paramPtr: XCmdPtr); forward;
  32.  
  33. procedure EntryPoint(paramPtr: XCmdPtr);
  34.  
  35.     begin
  36.         SPortConfiguration(paramPtr);
  37.     end;
  38.  
  39. procedure SPortConfiguration(paramPtr: XCmdPtr);
  40.  
  41.     var theConfiguration: str255;
  42.         i: integer;
  43.  
  44.     procedure Fail(errMsg: Str255); { set theResult and quit }
  45.         begin
  46.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  47.             exit(SPortConfiguration);
  48.         end;
  49.  
  50.     {$I SPortUtil.inc}
  51.  
  52.     procedure concatStr(str: str255);
  53.  
  54.         begin
  55.             theConfiguration := Concat(theConfiguration,str);
  56.         end;
  57.  
  58.     procedure concatOnOff(name: str255; onOff: boolean);
  59.  
  60.         begin
  61.             concatStr(',');
  62.             concatStr(name);
  63.             if onOff then concatStr('On')
  64.             else concatStr('Off');
  65.         end;
  66.  
  67.     begin
  68.         if paramPtr^.paramCount <> 0 then Fail('parameter count is not 0');
  69.  
  70.         SetUpSPortGlobals;
  71.  
  72.         { Start with the port: }
  73.         if Globals^^.selectedPort = sPortA then theConfiguration := 'modemPort'
  74.         else theConfiguration := 'printerPort';
  75.  
  76.         with ThisSPort do
  77.             begin
  78.                 { Add in the baud rate: }
  79.                 case BitAnd(byteConfig,$3FF) of
  80.                     baud300: concatStr(',baud300');
  81.                     baud600: concatStr(',baud600');
  82.                     baud1200: concatStr(',baud1200');
  83.                     baud1800: concatStr(',baud1800');
  84.                     baud2400: concatStr(',baud2400');
  85.                     baud3600: concatStr(',baud3600');
  86.                     baud4800: concatStr(',baud4800');
  87.                     baud7200: concatStr(',baud7200');
  88.                     baud9600: concatStr(',baud9600');
  89.                     baud19200: concatStr(',baud19200');
  90.                     baud57600: concatStr(',baud57600');
  91.                     end;
  92.  
  93.                 { And the stop bits: }
  94.                 { This is what the following code should look like, but the compile doesn't seem to be able to handle it:
  95.                             case integer(BitAnd(byteConfig,$0C000)) of
  96.                                 stop10: concatStr(',stop10');
  97.                                 stop15: concatStr(',stop15');
  98.                                 stop20: concatStr(',stop20');
  99.                                 end;}
  100.                 i := BitAnd(byteConfig,$0C000);
  101.                 if i = stop10 then concatStr(',stop10')
  102.                 else if i = stop15 then concatStr(',stop15')
  103.                 else if i = stop20 then concatStr(',stop20');
  104.  
  105.                 { And the parity: }
  106.                 case integer(BitAnd(byteConfig,$03000)) of
  107.                     noParity: concatStr(',parityOff');
  108.                     oddParity: concatStr(',parityOdd');
  109.                     evenParity: concatStr(',parityEven');
  110.                     end;
  111.  
  112.                 { And the number of data bits: }
  113.                 case integer(BitAnd(byteConfig,$00C00)) of
  114.                     data5: concatStr(',data5');
  115.                     data6: concatStr(',data6');
  116.                     data7: concatStr(',data7');
  117.                     data8: concatStr(',data8');
  118.                     end;
  119.  
  120.                 { And flow control: }
  121.                 concatOnOff('XOnOut',shakes.fXOn <> 0);
  122.                 concatOnOff('CTSOut',shakes.fCTS <> 0);
  123.  
  124.                 { Misc. control parameters: }
  125.                 concatOnOff('linefeed',sendLFs);
  126.                 concatOnOff('echo',doEcho);
  127.                 concatOnOff('edit',doEdit);
  128.                 concatOnOff('strip',stripIncoming);
  129.                 concatOnOff('stripControls',stripControls);
  130.                 concatOnOff('autoWrap',autoWrap);
  131.             end;
  132.  
  133.         { Return the complete configuration. }
  134.         paramPtr^.returnValue := PasToZero(paramPtr,theConfiguration);
  135.     end;
  136. end.
  137.